package com.example.classes;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Class represents the connection between the datasource and the database.
 * @author Ankit Pasi
 */
class MyDBHelper extends SQLiteOpenHelper
{
    /**
     * Constructor.
     */
    public MyDBHelper(Context context)
    {
        super(context,DataBase.DATABASE_NAME,null,1);

    }

    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL(DataBase.DATABASE_CREATE);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(DataBase.class.getName(),
                "MYDBHELPER: Upgrading database from version " + oldVersion + " to "
                             + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + DataBase.TABLE_USER);
        onCreate(db);
    }

    public void deleteDatabase()
    {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(DataBase.TABLE_USER, "1", new String[] {});
        Log.d("WMS-DEBUG", "MYDBHELPER: Database table successfully deleted");
        db.close();
    }
}
